// 云函数入口文件
const cloud = require('wx-server-sdk')
const env = 'bbq-6gz7knah1c296b0f'
cloud.init(env)

const db = cloud.database({env})
// 云函数入口函数
exports.main = async (event) => {
  const OPEN_ID = cloud.getWXContext().OPENID

  const result = await db.collection('users').where({
    userId:OPEN_ID
  }).get()

  if(!result.data.length){    //查询不到openID
    return {
      code:401,
      msg:'账号未注册'
    }
  }

    //账号密码不匹配
  if(result.data[0].account !== event.account || result.data[0].password !==event.password){
    return{
      code:402,
      msg:'账号或密码错误'
    }
  }

  return result

}